use ../Intermediate/bank_lending_panel, clear 
drop country 
merge m:1 BankID using ../Raw/Bank_Sample/Bank_Country, keep(1 3) nogen
merge 1:1 BankID year using ../Intermediate/bank_ban_strength_yearly, keepusing(ban_intensity_new1 ban_intensity_initial has_coded_policy active_policy)

gen log_lend = log(debt)
gen post15 = year > 2015
sum ban_intensity_new1_max if has_coded_policy == 1 & year == 2020, detail
gen ban_intensity_new1_max_sd = ban_intensity_new1_max/`r(sd)'
egen rf_score = max(rf_average), by(BankID)
sum rf_score if has_coded_policy == 1 & year == 2020, detail
gen rf_score_sd = rf_score/`r(sd)'
egen rf_phaseout_score = max(rf_phaseout), by(BankID)
sum rf_phaseout_score if has_coded_policy == 1 & year == 2020, detail
gen rf_phaseout_score_sd = rf_phaseout_score/`r(sd)'
egen complexity_score = rowtotal(is_sens*)
egen complexity_score_max = max(complexity_score), by(BankID)
sum complexity_score_max if has_coded_policy == 1 & year == 2020, detail
gen complexity_score_max_sd = complexity_score_max/`r(sd)'
sum ban_intensity_initial_max if has_coded_policy == 1 & year == 2020, detail
gen ban_intensity_initial_max_sd = ban_intensity_initial_max/`r(sd)'
replace ban_intensity_initial_max_sd = 0 if missing(ban_intensity_initial_max_sd)
gen yearf = year if ban_intensity_initial > 0 & !missing(ban_intensity_initial)
egen active_policy_start_initial = min(yearf), by(BankID)
gen active_policy_initial = year >= active_policy_start_initial


label var active_policy                           "$\\mathds{1}\\{ \\textrm{Has Exit Policy}\\}_{b,t}$"
label var post15                                   "$\\mathds{1}\\{\\textrm{Year} \\geq 2015\\}$"
label var ban_intensity_new1_max_sd               "$\\text{Max Strength}_{b}$"
label var rf_score_sd                             "$\\text{Max Strength (RF)}_{b}$"
label var rf_phaseout_score_sd                    "$\\text{Max Strength (RF Phaseout)}_{b}$"
label var complexity_score_max_sd                 "$\\text{Max Strength (Complexity)}_{b}$"
label var ban_intensity_initial_max_sd            "$\\text{Max Strength (Non-Updated)}_{b}$"
label var active_policy_initial                    "$\\mathds{1}\\{ \\textrm{Has Exit Policy (Non-Updated)}\\}_{b,t}$"


save "../Intermediate/bank_financing_regressions", replace

